<template>
  <el-row>
    <el-col :span="12">
      <el-dialog
        title="移交操作"
        :visible="status"
        class="dialog"
        @close="guanbi()"
        @open="getData()"
      >
        <el-form :model="yijiaoData" :rules="rules" ref="yijiaoData" label-width="150px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="办案单位" prop="huId">
                <el-select v-model="yijiaoData.huId">
                  <el-option
                    v-for="(item, index) in uhIdList"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="物品名称" prop="pName">
                <el-input v-model="yijiaoData.pName" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="物品处置">
                <el-input value="移交" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="移交对象" prop="name">
                <el-input v-model="yijiaoData.name"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item prop="toHuId">
                <el-input
                  v-model="yijiaoData.toHuId"
                  placeholder="财政部门ID/执法单位ID"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="公告时间" prop="bulletinTime">
                <el-date-picker
                  v-model="yijiaoData.bulletinTime"
                  type="date"
                  placeholder="选择公告时间"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12"> </el-col>
            <el-col :span="12">
              <el-form-item label="到期时间" prop="pastDueTime">
                <el-date-picker
                  v-model="yijiaoData.pastDueTime"
                  type="date"
                  placeholder="选择到期时间"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item prop="toUnit">
                <el-input v-model="yijiaoData.toUnit" placeholder="输入单位"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="到期提醒联系人" prop="pastDueContact">
                <el-input v-model="yijiaoData.pastDueContact"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="到期提醒联系方式" prop="pastDuePhone">
                <el-input v-model="yijiaoData.pastDuePhone"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="10">
              <el-form-item label="公告照片" class="imgbox" prop="bulletinImg">
                <image-upload v-model="yijiaoData.bulletinImg" />
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="财政签收照片" class="imgbox" prop="signInImg">
                <image-upload v-model="yijiaoData.signInImg"></image-upload>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-button type="primary" size="medium" @click="updateStatus_yijiao('yijiaoData')"
                >确认</el-button
              >
            </el-col>
          </el-row>
        </el-form>
      </el-dialog>
    </el-col>
  </el-row>
</template>
<script>
import { updateInfo, financialInfo } from '@/api/system/financial_treatment'
import { addlist } from '@/api/system/financial_treatment'
import { getUnitListAll } from '@/api/property/unit.js'
import moment from 'moment'
export default {
  data() {
    return {
      status: false,
      data: [],
      uhIdList: [],
      yijiaoData: {
        // 办案单位
        huId: null,
        // 物品名称
        pName: null,
        // 移交对象
        name: null,
        //财政部门/执法单位
        toHuId: null,
        // 公告时间
        bulletinTime: null,
        //财政-没收/无主物
        toFinancial: null,
        //到期时间
        pastDueTime: null,
        //输入单位
        toUnit: null,
        //到期提醒联系人
        pastDueContact: null,
        //到期提醒联系方式
        pastDuePhone: null,
        //公告照片
        bulletinImg: null,
        //财政签收照片
        signInImg: null,
        status: '2'
      },
      rules: {
        huId: [{ required: true, message: '请选择办案单位',  }],
        pName: [{ required: true, message: '请输入物品名称',  }],
        name: [{ required: true, message: '请输入移交对象姓名',  }],
        toHuId: [{ required: true, message: '请输入财政部门/执法单位',  }],
        bulletinTime: [{ required: true, message: '请输入公告时间',  }],
        toFinancial: [{ required: true, message: '请输入财政-没收/无主物',  }],
        pastDueTime: [{ required: true, message: '请输入到期时间',  }],
        toUnit: [{ required: Number, message: '请输入输入单位',  }],
        pastDueContact: [{ required: true, message: '请输入到期提醒联系人',  }],
        pastDuePhone: [{ required: true, message: '请输入到期提醒联系方式',  }],
        bulletinImg: [{ required: true, message: '请导入公告照片',  }],
        signInImg: [{ required: true, message: '请导入财政签收照片',  }]
      },
      pId: []
    }
  },
  methods: {
    updateStatus_yijiao(formName) {
      this.yijiaoData.bulletinTime = this.geshihuaDateTime(this.yijiaoData.bulletinTime)
      this.yijiaoData.pastDueTime = this.geshihuaDateTime(this.yijiaoData.pastDueTime)
      this.$refs[formName].validate((valid) => {
        if (valid) {
          //批量修改处置状态
          updateInfo(this.pId, 2).then((res) => {})

          //批量修改登记状态
          financialInfo(this.pId, 1).then((res) => {})

          // 添加处置数据
          addlist(this.yijiaoData).then((res) => {})

          this.status = false
          for (let key in this.yijiaoData) {
            this.yijiaoData[key] = ''
          }
        } else {
          alert('请填写完整!')
          return false
        }
      })
    },
    guanbi() {
      this.status = false
      for (let key in this.yijiaoData) {
        this.yijiaoData[key] = ''
      }
      this.$emit('genxing')
    },
    getData() {
      this.yijiaoData.pName = this.data.map((item) => item.pName).join(' ')
      this.data.map((item) => {
        this.pId.push(item.pId)
      })

      // 获取办案单位
      getUnitListAll().then((e) => {
        e.data.forEach((res) => {
          this.uhIdList.push({ label: res.name, value: res.id })
        })
      })

      //当事人
    },
    //时间格式化
    geshihuaDateTime(time) {
      return moment(time).format('YYYY-MM-DD HH:mm:ss')
    }
  }
}
</script>
